import { get, post } from '@/utils/request';

// 产品/内容相关类型定义
export interface FeedItem {
  id: number;
  feed_id: number | string;
  name: string;
  description: string;
  image: string;
  price?: number;
  rating?: number;
  user: {
    id: number;
    name: string;
    avatar: string;
  };
  counter: {
    like_count: number;
    comment_count: number;
    share_count: number;
    view_count: number;
    vote_count: number;
  };
  prize: {
    prize_type: number; // 1: 现金类，2: 实物类
    amount: string; // 金额
    name: string; // 奖品名称
  };
  is_vote?: number; // 投票状态：0-未投票，1-已投票
  like_flag?: number; // 点赞状态：0-未点赞，1-已点赞
  nex_status?: number; // nex状态 1: 进行中, 2: 已成功, 3: 已上架
  tags: any[];
  createdAt: string;
  updatedAt: string;
  thumbnail: {
    url: string;
    width: number;
    height: number;
  };
  caption: string;
  title: string;
  uid: string;
  enable_nex?: number; // 0开启nex 1关闭
}

// 定制商品列表
export interface ProductItem {
  product_id: string;
  product_info?: string;
  product_type?: number;
  prompt_text?: string;
  color?: string;
  cover?: string;
  description?: string[];
  imgs?: string[];
  size?: string;
  title?: string;
  url?: string;
  price?: string | number;
}

// 定制商品详情
export interface ProductDetailParams {
  product_id: string;
}

export interface FeedsParams {
  start?: number;
  size?: number;
  category?: string;
  keyword?: string;
  search_text?: string;
  sort_type?: string;
  category_id?: string | number;
  feed_id?: string | number;
  uid?: number | string;
  reason?: string;
  description?: string;
}

// 发布内容参数类型定义
export interface PublishFeedParams {
  title: string;
  caption: string;
  imgs: string[];
  thumbnail: string;
  enable_nex: number;
  prompt_status: number;
  prompt_text: string;
}

export interface PreviewImage {
  img: string[];
  showPreview: boolean;
  initialIndex: number;
}

/**
 * 内容/产品相关API
 */
export class FeedsAPI {
  /**
   * 获取推荐内容列表
   * @param params 查询参数
   * @returns Promise<any>
   */
  static async getFeatureFeeds(params: FeedsParams = {}) {
    const response = await post<any>('/feeds/feature', params);
    return response.data;
  }

  /**
   * 获取分类内容列表
   * @param category 分类
   * @param params 查询参数
   * @returns Promise<any>
   */
  static async getCategoryFeeds(category: string, params: FeedsParams = {}) {
    const response = await get<any>(`/feeds/category/${category}`, params);
    return response.data;
  }

  /**
   * 搜索内容
   * @param keyword 搜索关键词
   * @param params 查询参数
   * @returns Promise<any>
   */
  static async searchFeeds(keyword: string, params: FeedsParams = {}) {
    const response = await get<any>('/feeds/search', {
      keyword,
      ...params,
    });
    return response.data;
  }

  // 作品详情
  static async getFeed(params: FeedsParams = {}) {
    const response = await post<any>('/feeds/get_feed', params);
    return response;
  }

  static async getFeeds(params: FeedsParams = {}) {
    const response = await post<any>('/feeds/get_feeds', params);
    return response;
  }

  // 删除个人作品
  static async deleteFeed(params: FeedsParams = {}) {
    const response = await post<any>('/feeds/delete_feed', params);
    return response;
  }

  // 个人喜好作品
  static async getLikeFeeds(params: FeedsParams = {}) {
    const response = await post<any>('/feeds/get_like_feeds', params);
    return response;
  }

  /**
   * 发布内容
   * @param params 发布内容参数
   * @returns Promise<PublishFeedResponse>
   */
  static async publishFeed(params: PublishFeedParams) {
    const response = await post<any>('/feeds/publish', params);
    return response.data;
  }

  // 获取定制商品列表
  static async getProducts(params: FeedsParams = {}) {
    const response = await post<any>('/goods/get_products ', params);
    return response;
  }

  // 获取定制商品详情
  static async getProductDetail(params: ProductDetailParams) {
    const response = await post<any>('/goods/get_product_detail', params);
    return response;
  }

  // 举报作品
  static async reportProduct(params: FeedsParams) {
    const response = await post<any>('/feeds/report', params);
    return response;
  }
}
